<template>
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents">
			<view class="top-view status"></view>
		</view>
		<!-- #endif -->
		<view class="login-title">
			<view class="logo">
				<image src="/static/images/common/logo.png" mode=""></image>
			</view>
		</view>
		<view class="login-phone form-wapper">
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-shouji"></text></view>
				<view class="mobile rside">
					<u--form labelPosition="left" :model="model1" :rules="rules" ref="form1">
						<u-form-item prop="userInfo.name" ref="item1">
							<u--input v-model="username" placeholder="请输入手机号" border="none"></u--input>
						</u-form-item>
					</u--form>
				</view>
			</view>
			<view class="code input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="rside">
					<u--form labelPosition="left" :model="model1" :rules="rules" ref="form2">
						<u-form-item prop="userInfo.password" ref="item1">
							<u--input v-model="password" placeholder="请输入密码(6-12位)" border="none" type="password">
							</u--input>
						</u-form-item>
					</u--form>

				</view>
			</view>
			<view class="paw">
				<navigator :url="`/pages/public/code_login`">
					<view class="btn">验证码登录</view>
				</navigator>
			</view>
		</view>

		<button type="primary" class="login-btn" @click="login">登录</button>
		<view class="reg-paw">
			<text class="active" @click="skipReg">注册账号</text>
			<text @click="skipForget">忘记密码</text>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="quick">
			<view class="quick-title">
				<text class="line"></text>
				<text class="txt">快捷登陆</text>
				<text class="line"></text>
			</view>
			<view class="sanfang">
				<image src="../../static/temp/share_wechat.png" mode=""></image>
			</view>
		</view>
		<!-- #endif -->
	</view>
</template>
<script>
export default {
	data() {
		return {
			requt: 'https://4de16698-d9f4-443a-b416-ef1037cce952.bspapp.com/http',
			user: [],
			show: true,
			username: "",
			password: "",
			model1: {
				userInfo: {
				},
			},
			rules: {
				'userInfo.name': {
					type: 'string',
					required: true,
					pattern: /^1[3-9]\d{9}$/,
					message: '请填写手机号',
				},
				'userInfo.password': {
					type: 'string',
					required: true,
					message: '请填写密码',
				},
			},
			radio: '',
			switchVal: false
		};
	},
	onLoad() {
		// this.login()
	},
	methods: {
		//登录
		login() {
			// this.$refs.form1.validate().then(res => {
			// 	uni.$u.toast('校验通过')
			// }).catch(errors => {
			// 	uni.$u.toast('不能为空')
			// })
			// this.$refs.form2.validate().then(res => {
			// 	uni.$u.toast('校验通过')
			// }).catch(errors => {
			// 	uni.$u.toast('不能为空')
			// })

			uni.request({
				url: this.requt + '/user/login',
				method: "POST",
				data: {
					username: this.username,
					password: this.password
				},
				success: res => {
					console.log(res);
					this.$store.commit('change',{key:'uid',value:'uid'})
					this.$store.commit('change',{key:'userInfo',value:'userInfo'})
					this.$store.commit('change',{key:'username',value:'username'})
					this.$store.commit('change',{key:'token',value:'token'})
					if (res.data.code == 0) {
						uni.setStorageSync("token", res.data.token);
						uni.setStorageSync("uid", res.data.uid);
						uni.switchTab({
							url: '/pages/index/index'
						})
						//success
					} else {
						uni.$u.toast(res.data.msg|| "登录失败")
					}
				}
			})
		},
		skipReg(e) {
			uni.navigateTo({
				url: `/pages/public/reg`
			});
		},
		skipForget(e) {
			uni.navigateTo({
				url: `/pages/public/forget`
			});
		},

		submit() {
		}
	},
};
</script>
<style lang="scss">
@import 'login.scss';
</style>
